package com.yy.jhl.ui.manager.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yy.common.base.BaseAdapter;
import com.yy.jhl.R;
import com.yy.jhl.bean.InviteCodeInfo;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Ellis.Li on 2017/6/15.
 */

public class InviteCodeAdapter extends BaseAdapter {
    private List<InviteCodeInfo> modelList;
    public InviteCodeAdapter(Context context) {
        super(context);
        modelList = new ArrayList<>();
        modelList.add(new InviteCodeInfo());
        modelList.add(new InviteCodeInfo());
        modelList.add(new InviteCodeInfo());
        modelList.add(new InviteCodeInfo());
    }
    @Override
    public void removeItem(int position) {
        super.removeItem(position);
        modelList.remove(position);
        notifyDataSetChanged();
    }
    @Override
    public void clearData() {
        super.clearData();
        modelList.clear();
        notifyDataSetChanged();
    }
    public void addData(List<InviteCodeInfo> monomerModels) {
        modelList.addAll(monomerModels);
        notifyDataSetChanged();
    }

    public void addAllData(List<InviteCodeInfo> monomerModels) {
        clearData();
        modelList.addAll(monomerModels);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return modelList.size();
    }

    @Override
    public Object getItem(int i) {
        return modelList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        Holder storeHolder;
        if(view == null){
            storeHolder = new Holder();
            view = layoutInflater.inflate(R.layout.item_invite_code,null);
            storeHolder.initView(view);
            view.setTag(storeHolder);
        }else{
            storeHolder = (Holder)view.getTag();
        }
        final InviteCodeInfo itemModel = modelList.get(i);

        return view;
    }
    /**
     *
     */
    class Holder{
        private TextView invite_code_text;
        private TextView valid_time_text;
        private TextView send_time_text;
        void initView(View view) {
            invite_code_text = (TextView) view.findViewById(R.id.invite_code_text);
            valid_time_text = (TextView) view.findViewById(R.id.valid_time_text);
            send_time_text = (TextView) view.findViewById(R.id.send_time_text);
        }

    }
}
